package com.hbnu.collection;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author kittychen
 * @since 2025-10-14 15:16
 */
public class HashMapDemo {
    public static void main(String[] args) {
        Map<String, String> hashMap = new HashMap<>();

        hashMap.put("name", "kittychen");
        hashMap.put("age", "18");
        hashMap.put("sex", "male");
        hashMap.put("hobby", "eat");
        System.out.println(hashMap);

        System.out.println(hashMap.get("age"));  // 根据键获取值

        Set<String> keySet = hashMap.keySet();  // 获取所有的键
        for (String key : keySet) {
            System.out.println(key + " : " + hashMap.get(key));
        }

        Collection<String> values = hashMap.values();  // 获取所有的值
        for (String value : values) {
            System.out.println(value);
        }

        System.out.println(hashMap.containsKey("name"));
        System.out.println(hashMap.size());
    }
}
